if( selenium.browserbot.getCurrentWindow().close ) {
	
	// save the default close function
	selenium.browserbot.getCurrentWindow()._closeEvent = selenium.browserbot.getCurrentWindow().close;
	
	// override close function, for modal dialog, add steps to return value to its parent window
	selenium.browserbot.getCurrentWindow().close = function() {
		var childWin = selenium.browserbot.getCurrentWindow();
		
		// get the parent window
		var parentWin;
		if( childWin.opener ) {
			parentWin = childWin.opener;
		} else {
			parentWin = childWin.top.opener;
		}
		
		if( parentWin._modalRetVal == 'N.A.' ) { // it signs that the current window is a modal dialog
			// get the return value and pass it to parent window
			var retVal;
			if( childWin.returnValue ) {
				retVal = childWin.returnValue;
			} else {
				retVal = childWin.top.returnValue;
			}
			parentWin._getModalRetVal( retVal );
		}
		
		// close the window
		childWin._closeEvent();
		 
	};

}